<template>
  <div id="app">
    <div v-if="needInit">
      <input type="text" v-model="machineID">

      <button @click="initWebSocket">initWebSocket</button>
    </div>
    <router-view/>
  </div>
</template>

<script>
export default {
  name: 'App',
  data () {
      return {
          machineID: ''
      }
  },
  created () {
      if(localStorage.getItem('machineID')){
          this.machineID = localStorage.getItem('machineID');
          this.initWebSocket();
      }
  },
  methods: {
    initWebSocket () {
      if(!localStorage.getItem('machineID')){
        localStorage.setItem('machineID', this.machineID);
      }
      this.$socket.emit('machineID', this.machineID);
      this.$store.commit('setNeedInit', false);

    },
  },
  computed: {
    needInit: {
      get() {
        return this.$store.state.needInit;
      }
    }
  },
}
</script>

<style>
#app {
  font-family: 'Avenir', Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  color: #2c3e50;
  margin-top: 60px;
}
</style>
